import {invoke} from '@tauri-apps/api/tauri'
import {Group, Operation} from "../types";
import {WebviewWindow} from '@tauri-apps/api/window'

async function list_groups() {
    return await invoke<Group[]>('load_groups')
}

async function list_operations(group_id: number) {
    console.log(group_id, 'group_id')
    return await invoke<Operation[]>('load_operations', {
        groupId: group_id
    })
}

async function del_operation(id: number) {
    return await invoke<boolean>('del_operation', {
        operationId: id
    })
}

async function add_operation(operation: Operation) {
    return await invoke<boolean>('add_operation', {
        operation
    })
}

async function start_task(group_id: number, isLoop: boolean) {
    return await invoke<void>('start_task', {
        groupId: group_id,
        isLoop: isLoop
    })
}

async function hide_window() {
    const mainWindow = WebviewWindow.getByLabel('main')
    await mainWindow?.hide()
}

async function open_window() {
    const mainWindow = WebviewWindow.getByLabel('main')
    mainWindow?.show()
}

export {
    list_groups, list_operations, hide_window, open_window, start_task, del_operation,
    add_operation
}